package com.itheima.dubbo.web;

import com.itheima.dubbo.User;
import com.itheima.dubbo.UserFace;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.Method;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @Version: V1.0
 */
@RestController
@RequestMapping("user")
public class UserController {

    //@DubboReference    // 远程注入， 接口dubbo会为其实现代理对象
    @DubboReference(check = false)    // 启动检查
    //@DubboReference(loadbalance = "roundrobin", retries = 4)    // 负载均衡调用, 修改为：roundrobin 加权轮询
    //@DubboReference(cluster = "failfast", retries = 4)    // 集群容错
    //@DubboReference(url = "192.168.1.13:20880")    // dubbo 直连 服务提供方ip和服务提供方dubbo端口号
    //@DubboReference(version = "2.0.0")    // 灰度发布
    //@DubboReference(timeout = 100)    // 超时时间
    //@DubboReference(methods = {
    //        @Method(name = "findById",timeout = 20),
    //        @Method(name = "hello",timeout = 10000),
    //})    // 远程注入， 接口dubbo会为其实现代理对象
    private UserFace userFace;

    @GetMapping("hello")
    public String hello(String username) {

        String result = userFace.hello(username);
        return result;
    }


    @GetMapping("findOne")
    public User findOne(Long id) {
        RpcContext context = RpcContext.getContext();
        context.setAttachment("it", "Shanghai heima");
        User user = userFace.findById(new User(id, "上海"));
        return user;
    }
}
